package sc.client.world;

import java.io.IOException;

import sc.client.Client;
import sc.client.Interface;
import sc.datainterchange.CodedInputBuffer;

/**
 * Avatar
 * 
 * @author Stephen Carmody
 */
public class Avatar extends Container
{
	// Avatar object identity in data interchange
	private static final int OBJECTTYPEID = 1;
	
	public String name;
	public double height;
	
	/**
	 * Creates an instance of Avatar.
	 */
	public Avatar(String name)
	{
		this.name = name;
	}
	
	/**
	 * Receives "object" data and either creates or updates the corresponding
	 * object.
	 *   
	 * @param dataEvent
	 */
	public void read(CodedInputBuffer codedinput) throws IOException
	{
		super.read(codedinput);
		this.height = (double) codedinput.readRawVarint32() / Client.SCALE;

		// Update the camera if this is the players avatar
		if (this == Client.avatar)
		{
			Interface.camera.translate(-Interface.camera.T[3], -Interface.camera.T[7], -Interface.camera.T[11]);
			Interface.camera.translate(this.T[3], this.T[7], this.T[11]);
			// Camera is at eye level which is hard coded for now to be 10
			// centimetres lower than height.
			Interface.camera.moveUp(-Interface.camera.T[7]);
			Interface.camera.moveUp(this.height - 0.1f);
			Client.logger.info("Avatar height: " + this.height);
		}
	}

	@Override
	public String getID()
	{
		return "avatar:" + this.name;
	}	
	
}
